<?php

class Exts_Seo_SearchEngine {

	public function getReferer() {

		if( !isset($_SERVER['HTTP_REFERER'] )){
			return array();
		}
		
		$url = $_SERVER['HTTP_REFERER'];
		$results = array();
		$parts_url = parse_url($url);
		$results['host'] = $parts_url['host'];
		if( strpost($url, 'yahoo') || strpost($url, 'bing') || strpost($url, 'google') ) {
			
			$query = isset($parts_url['query']) ? $parts_url['query'] : (isset($parts_url['fragment']) ? $parts_url['fragment'] : '');
			if ($query) {
				parse_str($query, $parts_query);
				$results['query'] = 
					isset($parts_query['q']) ? $parts_query['q']
					: (isset($parts_query['p']) ? $parts_query['p'] : '');
			}
			$results['referer'] = $results['host'];
			
			return $results;
		}

		$results['query'] = '';
		$results['referer'] = $_SERVER['HTTP_REFERER'];
		return $results;
	}

}